package com.wpre.springblog;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * Created with IntelliJ IDEA.
 * Description:
 * User: LianBao
 * Date: 2024-10-21
 * Time: 19:59
 */

@RestController
@RequestMapping("/calc")
public class CalcController {
    //实现计算器功能:加法
    @RequestMapping("/sum")
    public String sum(@RequestParam("num1") Integer num1, @RequestParam("num2") Integer num2) {
        Integer sum = num1 + num2;
        return "计算结果:" + sum;
    }

    //减法
    @RequestMapping("/sub")
    public String sub(@RequestParam("num1") Integer num1, @RequestParam("num2") Integer num2) {
        Integer sum = num1 - num2;
        return "计算结果:" + sum;
    }


    //乘法
    @RequestMapping("/mul")
    public String mul(@RequestParam("num1") Integer num1, @RequestParam("num2") Integer num2) {
        Integer sum = num1 * num2;
        return "计算结果:" + sum;
    }
    //乘法
    @RequestMapping("/div")
    public String div(@RequestParam("num1") Integer num1, @RequestParam("num2") Integer num2) {
        if (num2==0) {
            return "num不能为0";
        }
        Integer sum = num1 / num2;
        return "计算结果:" + sum;
    }

}
